/**
 * 全局路由配置
 */
import Vue from 'vue'
import VueRouter from 'vue-router'
import BasicLayout from '../layout/BasicLayout.vue'
import UserLayout from '../layout/UserLayout.vue'

Vue.use(VueRouter)

// const routes = [
//   // // 1.登录
//   // {
//   //   path: '/login',
//   //   component: () => import(/* webpackChunkName: "login" */ '@/views/Login.vue'),
//   //   name: 'Login',
//   //   meta: { title: '登录 ' }
//   // },
//   // // 2.注册
//   // {
//   //   path: '/registry',
//   //   component: () => import(/* webpackChunkName: "login" */ '@/views/Registry.vue'),
//   //   name: 'Registry',
//   //   meta: { title: '注册' }
//   // },
//   // // 3. 仪表盘
//   // {
//   //   path: '/',
//   //   redirect: '/dashboard',
//   //   component: BasicLayout,
//   //   children: [
//   //     {
//   //       path: '/dashboard',
//   //       name: '仪表盘',
//   //       // 当 /dashboard 匹配成功
//   //       // Dashboard 组件会渲染在 BasicLayout 的 <router-view></router-view> 中
//   //       commponent: () => import(/* webpackChunkName: "dashboard" */ '../views/Dashboard.vue'),
//   //       meta: { title: '控制台', icon: 'el-icon-s-data' }
//   //     }
//   //   ]
//   // },
//   // // 项目管理
//   // {
//   //   path: '/project',
//   //   name: '项目管理',
//   //   component: BasicLayout,
//   //   redirect: '/project/my-project',
//   //   meta: { title: '项目管理', icon: 'el-icon-s-help' },
//   //   children: [
//   //     {
//   //       path: '/my-project',
//   //       name: '我的项目',
//   //       component: () => import(/* webpackChunkName: "projecct" */'@/views/MyProject.vue')
//   //     }
//   //   ]
//   // },
//   // { path: '/404', component: () => import(/* webpackChunkName: "login" */ '@/views/404.vue'), name: '404', meta: { title: '404未找到' } },
//   // // 404 page must be placed at the end !!!
//   // { path: '*', redirect: '@/views/404.vue', hidden: true }
// ]

const routes = [
  // constantRouter,采用嵌套路由的方式
  {
    path: '/user',
    component: UserLayout,
    redirect: '/user/login',
    hidden: true,
    children: [
      // /user/login
      {
        path: 'login',
        name: 'login',
        meta: { title: '登录' },
        component: () => import(/* webpackChunkName: "user" */ '@/views/user/Login')
      },
      // /user/register
      {
        path: 'register',
        name: 'register',
        meta: { title: '注册' },
        component: () => import(/* webpackChunkName: "user" */ '@/views/user/Register')
      },
      // /user/register-result
      {
        path: 'register-result',
        name: 'registerResult',
        meta: { title: '注册结果' },
        component: () => import(/* webpackChunkName: "user" */ '@/views/user/RegisterResult')
      }
    ]
  },
  // asyncRouter
  {
    path: '/',
    component: BasicLayout,
    children: [
      // dashboard
      {
        path: '/',
        redirect: '/dashboard/analysis'
      },
      {
        path: '/dashboard',
        name: 'dashboard',
        component: { render: h => h('router-view') },
        children: [
          {
            path: '/dashboard/analysis',
            name: 'analysis',
            component: () => import(/* webpackChunkName: "dashboard" */ '@/views/dashboard/Analysis')
          }
        ]
      },
      // project
      {
        path: '/project',
        name: 'project',
        component: { render: h => h('router-view') },
        children: [
          {
            path: '/project/my-project',
            name: 'my-project'
          }
        ]
      }
    ]
  },
  // 404
  {
    path: '/404',
    component: () => import(/* webpackChunkName: "fail" */ '@/views/404')
  },
  {
    path: '*',
    redirect: '@/views/404.vue',
    hidden: true
  }
]

const router = new VueRouter({
  mode: 'history',
  routes
})

export default router
